package com.zxy.demo.config;

import org.quartz.Scheduler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * QuartzConfig
 * <br/>其实springboot已经给实例化好了下面这个2个对象,可以不用写这个配置类,直接在代码中注入Scheduler。
 * <br/>但是为了更好的定制化开发,还是自己写这2个对象的实例化代码。
 * @author ZENG.XIAO.YAN
 * @version 1.0
 */
@Configuration
public class QuartzConfig {
	
	@Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean factory = new SchedulerFactoryBean();
        factory.setAutoStartup(true);
        factory.setStartupDelay(5);		// 延时5秒启动
        System.out.println("-----schedulerFactoryBean---instance");
        return factory;
    }
	
	@Bean
    public Scheduler scheduler(SchedulerFactoryBean schedulerFactoryBean){
		Scheduler scheduler = schedulerFactoryBean.getScheduler();
		System.out.println("scheduler---" + scheduler);
        return scheduler;
    }

}
